package web;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson.JSON;

import beans.PersonInformation;
import beans.Searcher;
import serviceimpl.SearchPeopleIpmt;
@WebServlet("/SearchServlet")
public class SearchServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Searcher search=new Searcher();
		try {
			BeanUtils.populate(search, request.getParameterMap());
			SearchPeopleIpmt service = new SearchPeopleIpmt ();
			List<PersonInformation> list = service.searchPeople(search);
			response.setCharacterEncoding("utf-8");
			HttpSession session = request.getSession();
			session.setAttribute("peoples", list);
			response.sendRedirect("/zzLoveProduct/search/Search.jsp");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
